﻿using System;
using System.ComponentModel;
using System.Windows;
using Tools.beans;
using Tools.FileUtills;

namespace Tools
{
    public partial class SettingExeInfo : Window
    {
        /// <summary>
        ///  当前选中的 文件名称
        /// </summary>
        public static  String CurrentFileName { get ; set; }



        //public UpdateInfo UpdateInfo { get; set; }
        

        /// <summary>
        ///  当前选中的 文件路径
        /// </summary>
        public static String CurrnetFilePath { get; set; }

        public SettingExeInfo()
        {
            InitializeComponent();

            this.DataContext = new UpdateInfo()
            {
                NewsFileName = ""
            };



        }

        public void UpdateFileName(Object o  , EventArgs args)
        {
            var updateInfo = this.DataContext as UpdateInfo;
            if (updateInfo == null || updateInfo.NewsFileName == null || "".Equals(updateInfo.NewsFileName))
            {
                MessageBox.Show("文件名称不能为空");
                return;
            }
            
            // 开始修改这个文件 

            if (FileUtils.updateItemInfo(CurrnetFilePath, CurrentFileName, updateInfo.NewsFileName))
            {
                MessageBox.Show("文件名称修改成功");
                Close();
            }
            Console.WriteLine(updateInfo.NewsFileName);
        }


        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            MainWindow mainWindow = new MainWindow();
            mainWindow.Show();
        }
    }
}